//
//  ViewController.m
//  27-ArrayDataSource
//
//  Created by mafeng on 16/8/19.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"
#import "ArrayDataSource.h"

@interface ViewController ()<UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableVeiw;
@property (nonatomic, strong) NSArray *array;
@property (nonatomic, strong) ArrayDataSource *arrayDataSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self handleData];
    // arrayDataSource 替代ViewController的数据源工作
    
    self.arrayDataSource = [ArrayDataSource arrayDataSourceWithTableCellReuse:@"reuse" arrayDataSource:_array configCell:^(UITableViewCell * _Nonnull cell, NSString *  _Nonnull model) {
        cell.textLabel.text = model;
    }];
    
    self.tableVeiw = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    // tableview的数据源变为自定义的类
    // 所有的协议不一定只能指向self
    _tableVeiw.dataSource = _arrayDataSource;
    _tableVeiw.delegate = self;
    [self.view addSubview:_tableVeiw];
    [_tableVeiw registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
  
}

- (void)handleData {
    
      self.array = @[ @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪", @"赵五一"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
